package com.ww.sound_emission.controller;

import com.ww.sound_emission.domain.Categories;
import com.ww.sound_emission.service.CategoriesService;
import com.ww.sound_emission.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/categories")
public class CategoryController {

    @Autowired
    private CategoriesService categoryService;

    // 获取所有分类
    @GetMapping
    public Result<List<Categories>> getAllCategories() {
        List<Categories> categories = categoryService.list();
        return Result.success(categories);
    }

    // 添加分类
    @PostMapping
    public Result<String> addCategory(@RequestBody Categories category) {
        categoryService.save(category);
        return Result.success("分类添加成功");
    }

    // 删除分类
    @DeleteMapping("/{id}")
    public Result<String> deleteCategory(@PathVariable Long id) {
        categoryService.removeById(id);
        return Result.success("分类删除成功");
    }
}